package com.cyf.db.mapper;

import com.cyf.db.bean.InParking;
import com.cyf.db.bean.Parking;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface InParkingMapper {

	// 出场时未识别车牌号，出现：一辆车进入多个停车场。 但是，同一辆车再次入场时，会将之前的入场信息置为无用信息，parkingcarmap也删除响应信息，故:下面不用list集合
	@Select("select p.* from local_inparking ip, parking p where ip.parkingId = p.id  and ip.status = 0 and ip.plate = #{plate} order by id desc limit 0, 1")
	Parking getParkingByPlate(@Param("plate") String plate);
	
	@Select("select * from local_inparking where plate = #{plate} and status = 0  order by id desc limit 0, 1")
    InParking getByPlate(@Param("plate") String plate);
	
	@Update("update local_inparking set wechatFee = #{inParking.wechatFee}, wechatTime = #{inParking.wechatTime}, wechatPayTime = #{inParking.wechatPayTime} where id = #{inParking.id}")
	void updateInParking(@Param("inParking") InParking inParking);

	@Select("select plate, primaryInTime, p.name parkingName from local_inparking i , parking p " +
			"where i.parkingId = p.id and i.primaryInTime >= #{startTime} and i.primaryInTime <= #{endTime} and i.status = 0 " +
			"and plate in (#{plate1},#{plate2},#{plate3})" +
			"order by primaryInTime desc limit #{start}, #{length}")
	List<InParking> getByTimeAndPlate(@Param("startTime") String startTime, @Param("endTime") String endTime,
                                      @Param("plate1") String plate1, @Param("plate2") String plate2, @Param("plate3") String plate3, @Param("start") int start, @Param("length") int length);

	/** 更新车场的锁定状态 **/
	@Update("update local_inparking set lockStatus = #{lockStatus} where id = #{id}")
    void updateLockStatus(@Param("lockStatus") Integer lockStatus, @Param("id") Integer id);

	@Select("select * from local_inparking where plate = #{plate} and parkingId = #{parkingId} and status = 0 order by id desc limit 0, 1")
	InParking getByPlateAndParkingId(@Param("plate") String plate, @Param("parkingId") Integer parkingId);
}
